package com.apes.pi.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * 管道参数
 *
 * @author wuq
 * @create 2019-10-19 10:32
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = PipeParams.CONST_TABLE_NAME)
public class PipeParams extends BaseModel {
    public static final String CONST_TABLE_NAME = "pi_Pipe_params";

    @Id
    @ApesGenerator(code = CONST_TABLE_NAME, name="PI管道参数")
    @Column(name = "id", nullable = false, length = 8)
    @Comment("管道参数编码")
    private String id;

    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "pipe_id", referencedColumnName = "id")
    @Comment("管道编码")
    private Pipe pipe;

    @Column(name = "name", length = 200) //, nullable = false
    @Comment("管道参数描述")
    private String name;    // 描述

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "type", referencedColumnName = "id")
    @Comment("参数类型")
    private Enumeration type; // 参数类型

    @Column(name = "value", nullable = false, length = 4000)
    @Comment("管道参数值")
    private String value;   // 值
}
